﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace dvd_xml
{
    public partial class EdytujKlienta : Form
    {
        private Klient k;
        public EdytujKlienta(Klient k)
        {
            InitializeComponent();
            this.k = k;
        }

        private void btnZapisz_Click(object sender, EventArgs e)
        {
            XDocument xmlDoc = XDocument.Load(Form1.PATH + "klienci.xml");
            XElement filmy = xmlDoc.Descendants("Klient").
                Where(fi => Convert.ToInt32(fi.Attribute("id").Value) == k.id).First();

            filmy.Element("Imie").Value = textBoxAddName.Text;
            filmy.Element("Nazwisko").Value = textBoxAddSurname.Text;
            filmy.Element("Adres").Value = textBoxAddAdress.Text;
            filmy.Element("Data_rejestracji").Value = dateTimePickerAdd.Text;

            xmlDoc.Save(Form1.PATH + "klienci.xml");

            Close();
        }

        private void btnAnuluj_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void EdytujKlienta_Load(object sender, EventArgs e)
        {
            textBoxAddName.Text = k.Imie;
            textBoxAddSurname.Text = k.Nazwisko;
            textBoxAddAdress.Text = k.Adres;
            dateTimePickerAdd.Text = k.Data_rejestracji;
        }
    }
}
